/**
 * Copyright (c) 2006-2008, Julien PORTALIER
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright  Copyright (c) 2006-2008, Julien PORTALIER
 * @link       http://feather-cm.google.com/
 * @license    http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

_gettext_add_translations("fr",
{
	'Link': 'Lien',
	'Expand textarea':            'Agrandir la zone de texte',
	'Shrink textarea':            'Réduire la zone de texte',
	'Emphasis (Ctrl+I)':          'Emphase (Ctrl+I)',
	'Bold (Ctrl+B)':              'Gras (Ctrl+B)',
	'Underline (Ctrl+U)':         'Souligner (Ctrl+U)',
	'Deleted (Ctrl+D)':           'Barré (Ctrl+D)',
	'Blockquote (Ctrl+Q)':        'Bloc de citation (Ctrl+Q)',
	'Create link (Ctrl+L)':       'Créer un lien (Ctrl+L)',
	'Add an image, video or music (Ctrl+M)':     'Ajouter une image, vidéo ou de la musique (Ctrl+M)',
	'Enter the URL to point to:': "Entrez l'URL vers laquelle le lien doit pointer :",
	'Enter link text:':           "Entrez le titre du lien :",
	'Enter image, video or music location URL:':  "Entrez l'URL de l'image, vidéo ou de la musique :"
});

Toolbar.MarkdownSyntax = Toolbar.Text.extend(
{
	initialize: function(textarea)
	{
		this.buttons = [
			['bold',      null, 'b'],
			['italic',    null, 'i'],
			['underline', null, 'u'],
			['del',       null, 'd'],
			[],
			['link',      null, 'l'],
			[],
			['files',     null, 'm'],
			['help',      null, 'h']
		];
		this.parent(textarea);
	},
	
	create: function()
	{
		// toolbar
		this.toolbar = new Element('span', {'class': this.options.className});
		
		this.addButton('bold',      _('Strong (Ctrl+B)'),    'A', {'font-weight':     'bold'});
		this.addButton('italic',    _('Emphasis (Ctrl+I)'),  'A', {'font-style':      'italic'});
		this.addButton('underline', _('Underline (Ctrl+U)'), 'A', {'text-decoration': 'underline'});
		this.addButton('del',       _('Deleted (Ctrl+D)'),   'A', {'text-decoration': 'line-through'});
		this.addButton('link',      _('Create link (Ctrl+L)'), _('Link'));
		
		// inject it
		this.toolbar.injectBefore(this.textarea);
		
		// action bar
		/*
		this.actions = new Element('span', {'class': 'actions'});
		this.actions.appendChild(new Element('a', {
			'href':  location.protocol + '//' + location.hostname.replace(/^([^.]+[.])/, '') + '/help/webcomics/pages',
			'class': 'help',
			'title': _('Do you need help?')
		}).setText(_('Need help?')));
		
		this.actions.addEvent('click', this.action.bindWithEvent(this));
		
		// inject it
		this.actions.injectBefore(this.textarea);
		*/
	},
	
	// callbacks
	
	cb_italic:    function() { this.encloseSelection('//'); },
	cb_bold:      function() { this.encloseSelection('**'); },
	cb_underline: function() { this.encloseSelection('__'); },
	cb_del:       function() { this.encloseSelection('<del>', '</del>'); },
	
	cb_quote: function()
	{
		this.selectionStartLinesWith('> ');
	},
	
	cb_pre: function()
	{
		this.selectionStartLinesWith('    ');
	},
	
	/**
	 * @todo Make something fancier.
	 * @todo Add possibility to enter a title attribute.
	 */
	cb_link: function()
	{
		// URL
		var url = prompt(_("Enter the URL to point to:"));
		if (url)
		{
			url = url.trim();
			
			// TEXT
			var text = this.getSelection();
			if (!text)
				text = prompt(_('Enter link text:'));
			
			this.replaceSelection('"' + text + '":' + url);
		}
	},
	
	/**
	 * @todo Make someting fancier (linked with filer).
	 */
	cb_media: function()
	{
		// URL
		var url = prompt(_('Enter image location URL:'));
		if (url)
		{
			url = url.trim();
			
			// ALT
			var alt = this.getSelection();
			if (alt)
				alt = '|' + alt;
			this.replaceSelection('{{' + url + (alt ? '|' + alt : '') + '}}');
		}
	},
	
	cb_help: function()
	{
		window.open('/help/syntax?layout=popup', 'help', 'width=500,height=400');
	}
});
/*
window.addEvent('domready', function()
{
	$$('textarea.toolbar, p.toolbar textarea').each(function(textarea)
	{
		if (!textarea.hasClass('fake'))
			new Toolbar.MarkdownSyntax(textarea);
	});
});
*/